﻿using CNKI.TPI.Web.Admin.IDAO;
using CNKI.TPI.Web.Admin.Model;
using CNKI.TPI.Web.Base;
using KNet.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace CNKI.TPI.Web.Admin.DAO
{
    public class SubjectHomeDao : BaseDAO, ISubjectHomeDao
    {
       /// <summary>
       /// 根据查询条件获取专题分页数据
       /// </summary>
       /// <param name="match"></param>
       /// <param name="start"></param>
       /// <param name="length"></param>
       /// <param name="count"></param>
       /// <returns></returns>
        public IList<SYS_CMS_TOPIC> GetTopicByWherePageSize(string name, int start, int length, out int count)
        {
            count = 0;
            IList<SYS_CMS_TOPIC> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC> exp = new ExpressionCombine<SYS_CMS_TOPIC>();
                Expression<Func<SYS_CMS_TOPIC, bool>> match = null; //查询条件
                exp.And("topicstatus", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(name))
                {
                    exp.And("TopicName", OperatorType.Equal, name);
                }
                match = exp.Compile();
                result = Context.Gets<SYS_CMS_TOPIC>(match, start, length, out count);
             
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 添加专题
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool InsertTopic(SYS_CMS_TOPIC obj)
        {
            bool result = false;
            try
            {
                result = Context.Insert<SYS_CMS_TOPIC>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 更新专题
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool UpdateTopic(SYS_CMS_TOPIC obj)
        {
            bool result = false;
            try
            {
                result = Context.Update<SYS_CMS_TOPIC>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 删除专题
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public bool DeleteSubject(string sysidstr)
        {
            bool result = false;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "update  SYS_CMS_TOPIC set topicstatus=9,domain='' where sysid =(" + sysidstr + ")";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        public IList<SYS_CMS_TOPIC> GetSubject(string sysidstr)
        {
            IList<SYS_CMS_TOPIC> listobj = null;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "select * from SYS_CMS_TOPIC  where sysid =(" + sysidstr + ")";
                listobj = Context.ExecuteSql<SYS_CMS_TOPIC>(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return listobj;
        }

        /// <summary>
        /// 根据查询条件查询专题数据
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC> GetSubjectByName(string name)
        {
            IList<SYS_CMS_TOPIC> result = null;
            ExpressionCombine<SYS_CMS_TOPIC> exp = new ExpressionCombine<SYS_CMS_TOPIC>();
            Expression<Func<SYS_CMS_TOPIC, bool>> match = null; //查询条件
            exp.And("topicstatus", OperatorType.Equal, 1);
            if (!String.IsNullOrEmpty(name))
            {
                exp.And("TopicName", OperatorType.Equal, name);
            }
            match = exp.Compile();
            result = Context.Get<SYS_CMS_TOPIC>(match);
            return result;
        }
        /// <summary>
        /// 根据导航名称查询导航数据
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_CLS> GetNavByName(string name)
        {
            IList<SYS_CMS_TOPIC_CLS> result = null;
            ExpressionCombine<SYS_CMS_TOPIC_CLS> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS>();
            Expression<Func<SYS_CMS_TOPIC_CLS, bool>> match = null; //查询条件
            exp.And("clsstatus", OperatorType.Equal, 1);
            if (!String.IsNullOrEmpty(name))
            {
                exp.And("CLSName", OperatorType.Equal, name);
            }
            match = exp.Compile();
            result = Context.Get<SYS_CMS_TOPIC_CLS>(match);
            return result;
        }

        public IList<SYS_CMS_TOPIC_DBCONFIG> GetDBByName(string name)
        {
            IList<SYS_CMS_TOPIC_DBCONFIG> result = null;
            ExpressionCombine<SYS_CMS_TOPIC_DBCONFIG> exp = new ExpressionCombine<SYS_CMS_TOPIC_DBCONFIG>();
            Expression<Func<SYS_CMS_TOPIC_DBCONFIG, bool>> match = null; //查询条件
            exp.And("status", OperatorType.Equal, 1);
            if (!String.IsNullOrEmpty(name))
            {
                exp.And("Name", OperatorType.Equal, name);
            }
            match = exp.Compile();
            result = Context.Get<SYS_CMS_TOPIC_DBCONFIG>(match);
            return result;
        }

        public IList<SYS_CMS_TOPIC_DBCONFIG> GetDBBySysId(string sysid)
        {
            IList<SYS_CMS_TOPIC_DBCONFIG> result = null;
            ExpressionCombine<SYS_CMS_TOPIC_DBCONFIG> exp = new ExpressionCombine<SYS_CMS_TOPIC_DBCONFIG>();
            Expression<Func<SYS_CMS_TOPIC_DBCONFIG, bool>> match = null; //查询条件
            exp.And("status", OperatorType.Equal, 1);
            if (!String.IsNullOrEmpty(sysid))
            {
                exp.And("SYSID", OperatorType.Equal, sysid);
            }
            match = exp.Compile();
            result = Context.Get<SYS_CMS_TOPIC_DBCONFIG>(match);
            return result;
        }
        /// <summary>
        /// 根据查询条件获取导航分类数据
        /// </summary>
        /// <param name="match"></param>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_CLS> GetNavByWherePageSize(string name, int start, int length, out int count)
        {
            count = 0;
            IList<SYS_CMS_TOPIC_CLS> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS>();
                Expression<Func<SYS_CMS_TOPIC_CLS, bool>> match = null; //查询条件
                exp.And("clsstatus", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(name))
                {
                    exp.And("CLSName", OperatorType.Equal, name);
                }
                match = exp.Compile();
                result = Context.Gets<SYS_CMS_TOPIC_CLS>(match, start, length, out count);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 根据查询条件获取数据源分类数据
        /// </summary>
        /// <param name="match"></param>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_DBCONFIG> GetDBByWherePageSize(string name, int start, int length, out int count)
        {
            count = 0;
            IList<SYS_CMS_TOPIC_DBCONFIG> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_DBCONFIG> exp = new ExpressionCombine<SYS_CMS_TOPIC_DBCONFIG>();
                Expression<Func<SYS_CMS_TOPIC_DBCONFIG, bool>> match = null; //查询条件
                exp.And("status", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(name))
                {
                    exp.And("Name", OperatorType.Equal, name);
                }
                match = exp.Compile();
                result = Context.Gets<SYS_CMS_TOPIC_DBCONFIG>(match, start, length, out count);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 添加专题导航
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool InsertNav(SYS_CMS_TOPIC_CLS obj)
        {
            bool result = false;
            try
            {
                result = Context.Insert<SYS_CMS_TOPIC_CLS>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public bool InsertDB(SYS_CMS_TOPIC_DBCONFIG obj)
        {
            bool result = false;
            try
            {
                result = Context.Insert<SYS_CMS_TOPIC_DBCONFIG>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        /// <summary>
        /// 更新专题导航
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool UpdateNav(SYS_CMS_TOPIC_CLS obj)
        {
            bool result = false;
            try
            {
                result = Context.Update<SYS_CMS_TOPIC_CLS>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public bool UpdateDB(SYS_CMS_TOPIC_DBCONFIG obj)
        {
            bool result = false;
            try
            {
                result = Context.Update<SYS_CMS_TOPIC_DBCONFIG>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 删除专题
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public bool DeleteNav(string sysidstr)
        {
            bool result = false;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "update SYS_CMS_TOPIC_CLS set clsstatus=9  where sysid =(" + sysidstr + ")";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public bool DeleteDB(string sysidstr)
        {
            bool result = false;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "update SYS_CMS_TOPIC_DBCONFIG set status=-1  where sysid =(" + sysidstr + ")";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public IList<SYS_CMS_TOPIC_CLS> GetBySysIDStr(string sysidstr)
        {
            IList<SYS_CMS_TOPIC_CLS> listobj = null;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "select * from SYS_CMS_TOPIC_CLS  where sysid =(" + sysidstr + ")";
                listobj = Context.ExecuteSql<SYS_CMS_TOPIC_CLS>(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return listobj;
        }
        
        /// <summary>
        /// 添加分类
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool InsertTopicClsNode(SYS_CMS_TOPIC_CLS_NODE obj)
        {
            bool result = false;
            try
            {
                result = Context.Insert<SYS_CMS_TOPIC_CLS_NODE>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 更新分类
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool UpdateTopicClsNode(SYS_CMS_TOPIC_CLS_NODE obj)
        {
            bool result = false;
            try
            {
                result = Context.Update<SYS_CMS_TOPIC_CLS_NODE>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 删除分类及子节点
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public bool DeleteCateNode(string sysidstr,string clscode)
        {
            bool result = false;
            try
            {
                string sql = "update  SYS_CMS_TOPIC_CLS_NODE set nodestatus=9 where clscode='"+clscode+"' and  syscode =(" + sysidstr + "?)";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        public bool DeleteByClsCode(string clscode)
        {
            bool result = false;
            try
            {
                string sql = "update  SYS_CMS_TOPIC_CLS_NODE set nodestatus=9 where clscode='" + clscode + "'";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 根据条件查询分类数据
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_CLS_NODE> GetCateByNavCode(string code)
        {
      
            IList<SYS_CMS_TOPIC_CLS_NODE> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS_NODE> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS_NODE>();
                Expression<Func<SYS_CMS_TOPIC_CLS_NODE, bool>> match = null; //查询条件
                exp.And("nodestatus", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(code))
                {
                    exp.And("CLSCode", OperatorType.Equal, code);
                }
                match = exp.Compile();
                result = Context.Get<SYS_CMS_TOPIC_CLS_NODE>(match);
                foreach (SYS_CMS_TOPIC_CLS_NODE item in result)
                {
                    item.CLSCode = StringHelper.ConvertHighlightFlag(item.CLSCode);
                }
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 获取下一个分类编码
        /// </summary>
        /// <param name="clscode"></param>
        /// <param name="parentcode"></param>
        /// <param name="grade"></param>
        /// <returns></returns>
        public string GetNextCateCode(string clscode, string parentcode, int grade)
        {
            string deptcode = "0001";
            string sql = "SELECT * FROM SYS_CMS_TOPIC_CLS_NODE where  clscode= " + clscode + " and syscode=" + parentcode + "? and grade=" + grade + " order by syscode desc";
            IList<SYS_CMS_TOPIC_CLS_NODE> obj = null;
            obj = Context.ExecuteSql<SYS_CMS_TOPIC_CLS_NODE>(sql);

            if (obj != null && obj.Count > 0)
            {
                string strTempSysCode = obj[0].NodeCode;
                deptcode = (Convert.ToInt32(strTempSysCode) + 1).ToString();
                int nCodeLength = deptcode.Length;
                for (int i = 0; i < 4 - nCodeLength; i++)
                {
                    deptcode = "0" + deptcode;
                }
            }
            return deptcode;
        }
        public bool UpdateNavCateChild(string clscode, string syscode, int flage)
        {
            bool result = false;
            try
            {
                string sql = "update SYS_CMS_TOPIC_CLS_NODE set CHILDFLAG=" + flage + "    where nodestatus=1 and clscode=" + clscode + " and  syscode=" + syscode;
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

       /// <summary>
       /// 更新分类名称
       /// </summary>
       /// <param name="sysid"></param>
       /// <param name="name"></param>
       /// <returns></returns>
        public bool UpdateTopicClsNodeName(int sysid, string name)
        {
            bool result = false;
            try
            {
                string sql = "update SYS_CMS_TOPIC_CLS_NODE set nodename='" + name + "' where sysid=" + sysid;
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        /// <summary>
        /// 添加分类条件
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool InsertTopicQuery(SYS_CMS_TOPIC_CLS_QUERY obj)
        {
            bool result = false;
            try
            {
                result = Context.Insert<SYS_CMS_TOPIC_CLS_QUERY>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 编辑条件
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool UpdateTopicQuery(SYS_CMS_TOPIC_CLS_QUERY obj)
        {
            bool result = false;
            try
            {
                result = Context.Update<SYS_CMS_TOPIC_CLS_QUERY>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }


        /// <summary>
        /// 根据查询条件获取分类条件数据
        /// </summary>
        /// <param name="match"></param>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_CLS_QUERY> GetQueryByPageSize(string dbname, string nodecode, string navcode,int start, int length, out int count)
        {
            count = 0;
            IList<SYS_CMS_TOPIC_CLS_QUERY> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS_QUERY> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS_QUERY>();
                Expression<Func<SYS_CMS_TOPIC_CLS_QUERY, bool>> match = null; //查询条件
                exp.And("status", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(dbname))
                {
                    exp.And("DBName", OperatorType.Equal, dbname);
                }
                if (!String.IsNullOrEmpty(nodecode))
                {
                    exp.And("NodeCode", OperatorType.Equal, nodecode);
                }
                if (!String.IsNullOrEmpty(navcode))
                {
                    exp.And("ClsCode", OperatorType.Equal, navcode);
                }
                match = exp.Compile();
                result = Context.Gets<SYS_CMS_TOPIC_CLS_QUERY>(match, start, length, out count);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 删除分类条件
        /// </summary>
        /// <param name="sysidstr"></param>
        /// <returns></returns>
        public bool DeleteCateQuery(string sysidstr)
        {
            bool result = false;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "update SYS_CMS_TOPIC_CLS_QUERY set status=9 where sysid =(" + sysidstr + ")";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        public bool DelCateQueryByClsCode(string clscode)
        {
            bool result = false;
            try
            {
                string sql = "update SYS_CMS_TOPIC_CLS_QUERY set status=9 where clscode ='" +clscode+"'";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        public bool DelQueryByClsNodeCode(string clscode,string sysnodecode)
        {
            bool result = false;
            try
            {
                string sql = "update SYS_CMS_TOPIC_CLS_QUERY set status=9 where nodecode= '" + sysnodecode + "?' and clscode ='" + clscode + "'";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 根据查询条件获取分类条件数据
        /// </summary>
        /// <param name="match"></param>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_CLS_QUERY> GetQueryByDBNode(string dbcode, string nodecode)
        {
             IList<SYS_CMS_TOPIC_CLS_QUERY> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS_QUERY> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS_QUERY>();
                Expression<Func<SYS_CMS_TOPIC_CLS_QUERY, bool>> match = null; //查询条件
                exp.And("status", OperatorType.Equal, 1);
               
                if (!String.IsNullOrEmpty(dbcode))
                {
                    exp.And("DBCode", OperatorType.Equal, dbcode);
                }
                if (!String.IsNullOrEmpty(nodecode))
                {
                    exp.And("NodeCode", OperatorType.Equal, nodecode);
                }
                match = exp.Compile();
                result = Context.Get<SYS_CMS_TOPIC_CLS_QUERY>(match);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        public IList<SYS_CMS_TOPIC_CLS_QUERY> GetQueryByCLSCode(string nodecode,string clscode)
        {
            IList<SYS_CMS_TOPIC_CLS_QUERY> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS_QUERY> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS_QUERY>();
                Expression<Func<SYS_CMS_TOPIC_CLS_QUERY, bool>> match = null; //查询条件
                exp.And("status", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(clscode))
                {
                    exp.And("CLSCode", OperatorType.Equal, clscode);
                }
                if (!String.IsNullOrEmpty(nodecode))
                {
                    exp.And("NodeCode", OperatorType.Equal, nodecode); 
                }
                match = exp.Compile();
                result = Context.Get<SYS_CMS_TOPIC_CLS_QUERY>(match);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public IList<SYS_CMS_TOPIC_CLS_NODE> GetByCLSNodeCode(string clscode, string nodecode)
        {
            IList<SYS_CMS_TOPIC_CLS_NODE> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS_NODE> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS_NODE>();
                Expression<Func<SYS_CMS_TOPIC_CLS_NODE, bool>> match = null; //查询条件
                exp.And("nodestatus", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(clscode))
                {
                    exp.And("CLSCode", OperatorType.Equal, clscode);
                }
                if (!String.IsNullOrEmpty(nodecode))
                {
                    exp.And("SysCode", OperatorType.Equal, nodecode);
                }
                match = exp.Compile();
                result = Context.Get<SYS_CMS_TOPIC_CLS_NODE>(match);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }


        /// <summary>
        /// 根据查询条件获取SYS_CMS_TOPIC_PAGECONFIG数据
        /// </summary>
        /// <param name="match"></param>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_PAGECONFIG> GetPageConfigByPageSize(string columname, string topiccode, int start, int length, out int count)
        {
            count = 0;
            IList<SYS_CMS_TOPIC_PAGECONFIG> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_PAGECONFIG> exp = new ExpressionCombine<SYS_CMS_TOPIC_PAGECONFIG>();
                Expression<Func<SYS_CMS_TOPIC_PAGECONFIG, bool>> match = null; //查询条件
                Expression<Func<SYS_CMS_TOPIC_PAGECONFIG, bool>> order = null; //查询条件

                order = c => c.SORTNO.Asc();
                exp.And("status", OperatorType.Equal, 1);
                if (!String.IsNullOrEmpty(columname))
                {
                    exp.And("ColumnName", OperatorType.Equal, columname);
                }
                if (!String.IsNullOrEmpty(topiccode))
                {
                    exp.And("TopicCode", OperatorType.Equal, topiccode);
                
                }
                match = exp.Compile();
                result = Context.Gets<SYS_CMS_TOPIC_PAGECONFIG>(match, start, length, out count, order);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool InsertPageConfig(SYS_CMS_TOPIC_PAGECONFIG obj)
        {
            bool result = false;
            try
            {
                result = Context.Insert<SYS_CMS_TOPIC_PAGECONFIG>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool UpdatePageConfig(SYS_CMS_TOPIC_PAGECONFIG obj)
        {
            bool result = false;
            try
            {
                result = Context.Update<SYS_CMS_TOPIC_PAGECONFIG>(obj);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }


        public IList<SYS_CMS_TOPIC_PAGECONFIG> GetPageConfig(string sysid)
        {
            IList<SYS_CMS_TOPIC_PAGECONFIG> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_PAGECONFIG> exp = new ExpressionCombine<SYS_CMS_TOPIC_PAGECONFIG>();
                Expression<Func<SYS_CMS_TOPIC_PAGECONFIG, bool>> match = null; //查询条件
                if (!String.IsNullOrEmpty(sysid))
                {
                    exp.And("SYSID", OperatorType.Equal, sysid);
                    match = exp.Compile();
                }
                result = Context.Get<SYS_CMS_TOPIC_PAGECONFIG>(match);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public bool DeletePageConfig(string sysidstr)
        {
            bool result = false;
            sysidstr = sysidstr.Replace(',', '+');
            try
            {
                string sql = "update SYS_CMS_TOPIC_PAGECONFIG set status=9 where sysid =(" + sysidstr + ")";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        public bool DelageConfigByTopicCode(string topicCode)
        {
            bool result = false;
            try
            {
                string sql = "update SYS_CMS_TOPIC_PAGECONFIG set status=9 where topicCode ='" + topicCode + "'";
                result = Context.ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }
        /// <summary>
        /// 修改显示顺序
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool UpdatePageSort(IList<SYS_CMS_TOPIC_PAGECONFIG> list)
        {
            bool m = true;
            try
            {
                string sql = "";
                foreach (SYS_CMS_TOPIC_PAGECONFIG item in list)
                {
                    sql = " update SYS_CMS_TOPIC_PAGECONFIG set SortNo='" + item.SORTNO + "' where SYSID='" + item.SYSID + "'";
                    Context.ExecuteNonQuery(sql);
                }
            }
            catch
            {
                m = false;
            }
            return m;

        }

          /// <summary>
        /// 获取子节点
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public IList<SYS_CMS_TOPIC_CLS_NODE> GetCateChilds(string clscode, int grade, string syscode)
        {
            IList<SYS_CMS_TOPIC_CLS_NODE> result = null;
            try
            {
                ExpressionCombine<SYS_CMS_TOPIC_CLS_NODE> exp = new ExpressionCombine<SYS_CMS_TOPIC_CLS_NODE>();
                Expression<Func<SYS_CMS_TOPIC_CLS_NODE, bool>> match = null; //查询条件
                exp.And("nodestatus", OperatorType.Equal, 1);
                exp.And("grade", OperatorType.Equal, grade);
                exp.And("syscode", OperatorType.Equal, syscode + "?");
                if (!String.IsNullOrEmpty(clscode))
                {
                    exp.And("CLSCode", OperatorType.Equal, clscode);
                
                }
                match = exp.Compile();
                result = Context.Get<SYS_CMS_TOPIC_CLS_NODE>(match);
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

        public IList<SYS_CMS_TOPIC_PAGECONFIG> GetPageConfigAll()
        {
            IList<SYS_CMS_TOPIC_PAGECONFIG> result = null;
            try
            {
                result = Context.GetAll<SYS_CMS_TOPIC_PAGECONFIG>().Where(c=>c.STATUS==1).ToList();
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
            }
            return result;
        }

    }
}
